﻿using NH.Core.Interfaces;
using NHibernate.Cfg;
using NHibernate.Driver;

namespace NH.Data.Configs
{
    public abstract class DBConfig<TDialect, TDriver> : IConfig<Configuration>
        where TDialect : NHibernate.Dialect.Dialect
        where TDriver : IDriver
    {
        private readonly string connection;

        protected Configuration config;

        protected DBConfig(string connection)
        {
            this.connection = connection;
        }

        public virtual Configuration GetConfig()
        {
            config = new Configuration();
            config.DataBaseIntegration(
                x =>
                    {
                        x.Dialect<TDialect>();
                        x.Driver<TDriver>();
                        x.LogSqlInConsole = true;
                        x.LogFormattedSql = true;
                        x.ConnectionString = connection;
                    });

            return config;
        }
    }
}